﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//请先添加引用
namespace FiberRMS.DAL.AlarmManager
{
    /// <summary>
    /// 数据访问类ALARM_INFO。
    /// </summary>
    public class ALARM_INFO
    {
        /// <summary>
        /// 
        /// </summary>
        public ALARM_INFO()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string ALARMNUMBER)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from ALARM_INFO");
            strSql.Append(" where ALARMNUMBER=:ALARMNUMBER ");
            OracleParameter[] parameters = {
					new OracleParameter(":ALARMNUMBER", OracleType.VarChar,50)};
            parameters[0].Value = ALARMNUMBER;

            return OracleHelper.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(FiberRMS.Model.AlarmManager.ALARM_INFO model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into ALARM_INFO(");
            strSql.Append("ALARMNUMBER,ENDTIME,ISCLEARED,CLEARPERSON,ALARMEXPLAIN,BELONGEQUIP,BELONGTRANSYS,BELONGSTATION,RECORDDATE,ALARMDESC,");
            strSql.Append(" PRIMALCAUSE,ALARMOBJECT,TRANTYPE,VENDOR,BELONGDOMAIN,EQUIPMODEL,PACKTYPE,PREEQUIP,PRESTATION,DEDUSEFAULT,PERSISTTIME,ISSYNC,");
            strSql.Append(" OBJECTCODE,OBJCLASS,ALARMTYPE,PROBABLECAUSE,ALARMTEXT,ALARMLEVEL,STARTTIME)");
            strSql.Append(" values (");
            strSql.Append(":ALARMNUMBER,:ENDTIME,:ISCLEARED,:CLEARPERSON,:ALARMEXPLAIN,:BELONGEQUIP,:BELONGTRANSYS,:BELONGSTATION,:RECORDDATE,:ALARMDESC,:PRIMALCAUSE,");
            strSql.Append(" :ALARMOBJECT,:TRANTYPE,:VENDOR,:BELONGDOMAIN,:EQUIPMODEL,:PACKTYPE,:PREEQUIP,:PRESTATION,:DEDUSEFAULT,:PERSISTTIME,:ISSYNC,:OBJECTCODE,");
            strSql.Append(" :OBJCLASS,:ALARMTYPE,:PROBABLECAUSE,:ALARMTEXT,:ALARMLEVEL,:STARTTIME)");
            OracleParameter[] parameters = {
					new OracleParameter(":ALARMNUMBER", OracleType.VarChar,20),
					new OracleParameter(":ENDTIME", OracleType.DateTime),
					new OracleParameter(":ISCLEARED", OracleType.VarChar,2),
					new OracleParameter(":CLEARPERSON", OracleType.VarChar,20),
					new OracleParameter(":ALARMEXPLAIN", OracleType.VarChar,255),
					new OracleParameter(":BELONGEQUIP", OracleType.VarChar,255),
					new OracleParameter(":BELONGTRANSYS", OracleType.VarChar,100),
					new OracleParameter(":BELONGSTATION", OracleType.VarChar,65),
					new OracleParameter(":RECORDDATE", OracleType.DateTime),
					new OracleParameter(":ALARMDESC", OracleType.VarChar,255),
					new OracleParameter(":PRIMALCAUSE", OracleType.VarChar,100),
					new OracleParameter(":ALARMOBJECT", OracleType.VarChar,64),
					new OracleParameter(":TRANTYPE", OracleType.VarChar,3),
					new OracleParameter(":VENDOR", OracleType.VarChar,20),
					new OracleParameter(":BELONGDOMAIN", OracleType.VarChar,20),
					new OracleParameter(":EQUIPMODEL", OracleType.VarChar,12),
					new OracleParameter(":PACKTYPE", OracleType.VarChar,20),
					new OracleParameter(":PREEQUIP", OracleType.VarChar,33),
					new OracleParameter(":PRESTATION", OracleType.VarChar,20),
					new OracleParameter(":DEDUSEFAULT", OracleType.VarChar,1),
					new OracleParameter(":PERSISTTIME", OracleType.VarChar,64),
					new OracleParameter(":ISSYNC", OracleType.VarChar,2),
					new OracleParameter(":OBJECTCODE", OracleType.VarChar,255),
					new OracleParameter(":OBJCLASS", OracleType.VarChar,40),
					new OracleParameter(":ALARMTYPE", OracleType.VarChar,50),
					new OracleParameter(":PROBABLECAUSE", OracleType.VarChar,40),
					new OracleParameter(":ALARMTEXT", OracleType.VarChar,255),
					new OracleParameter(":ALARMLEVEL", OracleType.VarChar,32),
					new OracleParameter(":STARTTIME", OracleType.DateTime)};
            parameters[0].Value = model.ALARMNUMBER;
            parameters[1].Value = model.ENDTIME;
            parameters[2].Value = model.ISCLEARED;
            parameters[3].Value = model.CLEARPERSON;
            parameters[4].Value = model.ALARMEXPLAIN;
            parameters[5].Value = model.BELONGEQUIP;
            parameters[6].Value = model.BELONGTRANSYS;
            parameters[7].Value = model.BELONGSTATION;
            parameters[8].Value = model.RECORDDATE;
            parameters[9].Value = model.ALARMDESC;
            parameters[10].Value = model.PRIMALCAUSE;
            parameters[11].Value = model.ALARMOBJECT;
            parameters[12].Value = model.TRANTYPE;
            parameters[13].Value = model.VENDOR;
            parameters[14].Value = model.BELONGDOMAIN;
            parameters[15].Value = model.EQUIPMODEL;
            parameters[16].Value = model.PACKTYPE;
            parameters[17].Value = model.PREEQUIP;
            parameters[18].Value = model.PRESTATION;
            parameters[19].Value = model.DEDUSEFAULT;
            parameters[20].Value = model.PERSISTTIME;
            parameters[21].Value = model.ISSYNC;
            parameters[22].Value = model.OBJECTCODE;
            parameters[23].Value = model.OBJCLASS;
            parameters[24].Value = model.ALARMTYPE;
            parameters[25].Value = model.PROBABLECAUSE;
            parameters[26].Value = model.ALARMTEXT;
            parameters[27].Value = model.ALARMLEVEL;
            parameters[28].Value = model.STARTTIME;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(FiberRMS.Model.AlarmManager.ALARM_INFO model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update ALARM_INFO set ");
            strSql.Append("ENDTIME=:ENDTIME,");
            strSql.Append("ISCLEARED=:ISCLEARED,");
            strSql.Append("CLEARPERSON=:CLEARPERSON,");
            strSql.Append("ALARMEXPLAIN=:ALARMEXPLAIN,");
            strSql.Append("BELONGEQUIP=:BELONGEQUIP,");
            strSql.Append("BELONGTRANSYS=:BELONGTRANSYS,");
            strSql.Append("BELONGSTATION=:BELONGSTATION,");
            strSql.Append("RECORDDATE=:RECORDDATE,");
            strSql.Append("ALARMDESC=:ALARMDESC,");
            strSql.Append("PRIMALCAUSE=:PRIMALCAUSE,");
            strSql.Append("ALARMOBJECT=:ALARMOBJECT,");
            strSql.Append("TRANTYPE=:TRANTYPE,");
            strSql.Append("VENDOR=:VENDOR,");
            strSql.Append("BELONGDOMAIN=:BELONGDOMAIN,");
            strSql.Append("EQUIPMODEL=:EQUIPMODEL,");
            strSql.Append("PACKTYPE=:PACKTYPE,");
            strSql.Append("PREEQUIP=:PREEQUIP,");
            strSql.Append("PRESTATION=:PRESTATION,");
            strSql.Append("DEDUSEFAULT=:DEDUSEFAULT,");
            strSql.Append("PERSISTTIME=:PERSISTTIME,");
            strSql.Append("ISSYNC=:ISSYNC,");
            strSql.Append("OBJECTCODE=:OBJECTCODE,");
            strSql.Append("OBJCLASS=:OBJCLASS,");
            strSql.Append("ALARMTYPE=:ALARMTYPE,");
            strSql.Append("PROBABLECAUSE=:PROBABLECAUSE,");
            strSql.Append("ALARMTEXT=:ALARMTEXT,");
            strSql.Append("ALARMLEVEL=:ALARMLEVEL,");
            strSql.Append("STARTTIME=:STARTTIME");
            strSql.Append(" where ALARMNUMBER=:ALARMNUMBER ");
            OracleParameter[] parameters = {
					new OracleParameter(":ALARMNUMBER", OracleType.VarChar,20),
					new OracleParameter(":ENDTIME", OracleType.DateTime),
					new OracleParameter(":ISCLEARED", OracleType.VarChar,2),
					new OracleParameter(":CLEARPERSON", OracleType.VarChar,20),
					new OracleParameter(":ALARMEXPLAIN", OracleType.VarChar,255),
					new OracleParameter(":BELONGEQUIP", OracleType.VarChar,255),
					new OracleParameter(":BELONGTRANSYS", OracleType.VarChar,100),
					new OracleParameter(":BELONGSTATION", OracleType.VarChar,65),
					new OracleParameter(":RECORDDATE", OracleType.DateTime),
					new OracleParameter(":ALARMDESC", OracleType.VarChar,255),
					new OracleParameter(":PRIMALCAUSE", OracleType.VarChar,100),
					new OracleParameter(":ALARMOBJECT", OracleType.VarChar,64),
					new OracleParameter(":TRANTYPE", OracleType.VarChar,3),
					new OracleParameter(":VENDOR", OracleType.VarChar,20),
					new OracleParameter(":BELONGDOMAIN", OracleType.VarChar,20),
					new OracleParameter(":EQUIPMODEL", OracleType.VarChar,12),
					new OracleParameter(":PACKTYPE", OracleType.VarChar,20),
					new OracleParameter(":PREEQUIP", OracleType.VarChar,33),
					new OracleParameter(":PRESTATION", OracleType.VarChar,20),
					new OracleParameter(":DEDUSEFAULT", OracleType.VarChar,1),
					new OracleParameter(":PERSISTTIME", OracleType.VarChar,64),
					new OracleParameter(":ISSYNC", OracleType.VarChar,2),
					new OracleParameter(":OBJECTCODE", OracleType.VarChar,255),
					new OracleParameter(":OBJCLASS", OracleType.VarChar,40),
					new OracleParameter(":ALARMTYPE", OracleType.VarChar,50),
					new OracleParameter(":PROBABLECAUSE", OracleType.VarChar,40),
					new OracleParameter(":ALARMTEXT", OracleType.VarChar,255),
					new OracleParameter(":ALARMLEVEL", OracleType.VarChar,32),
					new OracleParameter(":STARTTIME", OracleType.DateTime)};
            parameters[0].Value = model.ALARMNUMBER;
            parameters[1].Value = model.ENDTIME;
            parameters[2].Value = model.ISCLEARED;
            parameters[3].Value = model.CLEARPERSON;
            parameters[4].Value = model.ALARMEXPLAIN;
            parameters[5].Value = model.BELONGEQUIP;
            parameters[6].Value = model.BELONGTRANSYS;
            parameters[7].Value = model.BELONGSTATION;
            parameters[8].Value = model.RECORDDATE;
            parameters[9].Value = model.ALARMDESC;
            parameters[10].Value = model.PRIMALCAUSE;
            parameters[11].Value = model.ALARMOBJECT;
            parameters[12].Value = model.TRANTYPE;
            parameters[13].Value = model.VENDOR;
            parameters[14].Value = model.BELONGDOMAIN;
            parameters[15].Value = model.EQUIPMODEL;
            parameters[16].Value = model.PACKTYPE;
            parameters[17].Value = model.PREEQUIP;
            parameters[18].Value = model.PRESTATION;
            parameters[19].Value = model.DEDUSEFAULT;
            parameters[20].Value = model.PERSISTTIME;
            parameters[21].Value = model.ISSYNC;
            parameters[22].Value = model.OBJECTCODE;
            parameters[23].Value = model.OBJCLASS;
            parameters[24].Value = model.ALARMTYPE;
            parameters[25].Value = model.PROBABLECAUSE;
            parameters[26].Value = model.ALARMTEXT;
            parameters[27].Value = model.ALARMLEVEL;
            parameters[28].Value = model.STARTTIME;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(string ALARMNUMBER)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete ALARM_INFO ");
            strSql.Append(" where ALARMNUMBER=:ALARMNUMBER ");
            OracleParameter[] parameters = {
					new OracleParameter(":ALARMNUMBER", OracleType.VarChar,50)};
            parameters[0].Value = ALARMNUMBER;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public FiberRMS.Model.AlarmManager.ALARM_INFO GetModel(string ALARMNUMBER)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ALARMNUMBER,ENDTIME,ISCLEARED,CLEARPERSON,ALARMEXPLAIN,BELONGEQUIP,BELONGTRANSYS,BELONGSTATION,RECORDDATE,ALARMDESC,");
            strSql.Append(" PRIMALCAUSE,ALARMOBJECT,TRANTYPE,VENDOR,BELONGDOMAIN,EQUIPMODEL,PACKTYPE,PREEQUIP,PRESTATION,DEDUSEFAULT,PERSISTTIME,ISSYNC,");
            strSql.Append(" OBJECTCODE,OBJCLASS,ALARMTYPE,PROBABLECAUSE,ALARMTEXT,ALARMLEVEL,STARTTIME from ALARM_INFO ");
            strSql.Append(" where ALARMNUMBER=:ALARMNUMBER ");
            OracleParameter[] parameters = {
					new OracleParameter(":ALARMNUMBER", OracleType.VarChar,50)};
            parameters[0].Value = ALARMNUMBER;

            FiberRMS.Model.AlarmManager.ALARM_INFO model = new FiberRMS.Model.AlarmManager.ALARM_INFO();
            DataSet ds = OracleHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.ALARMNUMBER = ds.Tables[0].Rows[0]["ALARMNUMBER"].ToString();
                if (ds.Tables[0].Rows[0]["ENDTIME"].ToString() != "")
                {
                    model.ENDTIME = DateTime.Parse(ds.Tables[0].Rows[0]["ENDTIME"].ToString());
                }
                model.ISCLEARED = ds.Tables[0].Rows[0]["ISCLEARED"].ToString();
                model.CLEARPERSON = ds.Tables[0].Rows[0]["CLEARPERSON"].ToString();
                model.ALARMEXPLAIN = ds.Tables[0].Rows[0]["ALARMEXPLAIN"].ToString();
                model.BELONGEQUIP = ds.Tables[0].Rows[0]["BELONGEQUIP"].ToString();
                model.BELONGTRANSYS = ds.Tables[0].Rows[0]["BELONGTRANSYS"].ToString();
                model.BELONGSTATION = ds.Tables[0].Rows[0]["BELONGSTATION"].ToString();
                if (ds.Tables[0].Rows[0]["RECORDDATE"].ToString() != "")
                {
                    model.RECORDDATE = DateTime.Parse(ds.Tables[0].Rows[0]["RECORDDATE"].ToString());
                }
                model.ALARMDESC = ds.Tables[0].Rows[0]["ALARMDESC"].ToString();
                model.PRIMALCAUSE = ds.Tables[0].Rows[0]["PRIMALCAUSE"].ToString();
                model.ALARMOBJECT = ds.Tables[0].Rows[0]["ALARMOBJECT"].ToString();
                model.TRANTYPE = ds.Tables[0].Rows[0]["TRANTYPE"].ToString();
                model.VENDOR = ds.Tables[0].Rows[0]["VENDOR"].ToString();
                model.BELONGDOMAIN = ds.Tables[0].Rows[0]["BELONGDOMAIN"].ToString();
                model.EQUIPMODEL = ds.Tables[0].Rows[0]["EQUIPMODEL"].ToString();
                model.PACKTYPE = ds.Tables[0].Rows[0]["PACKTYPE"].ToString();
                model.PREEQUIP = ds.Tables[0].Rows[0]["PREEQUIP"].ToString();
                model.PRESTATION = ds.Tables[0].Rows[0]["PRESTATION"].ToString();
                model.DEDUSEFAULT = ds.Tables[0].Rows[0]["DEDUSEFAULT"].ToString();
                model.PERSISTTIME = ds.Tables[0].Rows[0]["PERSISTTIME"].ToString();
                model.ISSYNC = ds.Tables[0].Rows[0]["ISSYNC"].ToString();
                model.OBJECTCODE = ds.Tables[0].Rows[0]["OBJECTCODE"].ToString();
                model.OBJCLASS = ds.Tables[0].Rows[0]["OBJCLASS"].ToString();
                model.ALARMTYPE = ds.Tables[0].Rows[0]["ALARMTYPE"].ToString();
                model.PROBABLECAUSE = ds.Tables[0].Rows[0]["PROBABLECAUSE"].ToString();
                model.ALARMTEXT = ds.Tables[0].Rows[0]["ALARMTEXT"].ToString();
                model.ALARMLEVEL = ds.Tables[0].Rows[0]["ALARMLEVEL"].ToString();
                if (ds.Tables[0].Rows[0]["STARTTIME"].ToString() != "")
                {
                    model.STARTTIME = DateTime.Parse(ds.Tables[0].Rows[0]["STARTTIME"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ALARMNUMBER,ENDTIME,ISCLEARED,CLEARPERSON,ALARMEXPLAIN,BELONGEQUIP,BELONGTRANSYS,BELONGSTATION,RECORDDATE,ALARMDESC,PRIMALCAUSE,");
            strSql.Append(" ALARMOBJECT,TRANTYPE,VENDOR,BELONGDOMAIN,EQUIPMODEL,PACKTYPE,PREEQUIP,PRESTATION,DEDUSEFAULT,PERSISTTIME,ISSYNC,OBJECTCODE,OBJCLASS,");
            strSql.Append(" ALARMTYPE,PROBABLECAUSE,ALARMTEXT,ALARMLEVEL,STARTTIME ");
            strSql.Append(" FROM ALARM_INFO ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by STARTTIME desc ");
            return OracleHelper.Query(strSql.ToString());
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetListByObject(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            //strSql.Append("select ALARMNUMBER,ENDTIME,ISCLEARED,CLEARPERSON,ALARMEXPLAIN,BELONGEQUIP,BELONGTRANSYS,BELONGSTATION,RECORDDATE,ALARMDESC,PRIMALCAUSE,ALARMOBJECT,TRANTYPE,VENDOR,BELONGDOMAIN,EQUIPMODEL,PACKTYPE,PREEQUIP,PRESTATION,DEDUSEFAULT,PERSISTTIME,ISSYNC,OBJECTCODE,OBJCLASS,ALARMTYPE,PROBABLECAUSE,ALARMTEXT,ALARMLEVEL,STARTTIME ");
            //strSql.Append(" FROM ALARM_INFO ");
            /*
             * 修改说明:上面SQL语句将一个对象的告警都查出了，现改为只查询对象的一个最高等级告警，以减少告警列表
             * 修改时间:2010.11.29 10:30
             * 修 改 人:qfkong
             * 修改说明:由于SQL语句编写错误，导致数据查询不出，只查询告警对象ID和告警等级
             * 修改时间:2010.12.8 15:00
             * 修 改 人:qfkong
             */
            //strSql.Append("select ALARMNUMBER,ENDTIME,ISCLEARED,CLEARPERSON,ALARMEXPLAIN,BELONGEQUIP,BELONGTRANSYS,BELONGSTATION,RECORDDATE,ALARMDESC,PRIMALCAUSE,");
            //strSql.Append(" ALARMOBJECT,TRANTYPE,VENDOR,BELONGDOMAIN,EQUIPMODEL,PACKTYPE,PREEQUIP,PRESTATION,DEDUSEFAULT,PERSISTTIME,ISSYNC,OBJECTCODE,OBJCLASS,");
            //strSql.Append(" ALARMTYPE,PROBABLECAUSE,ALARMTEXT,ALARMLEVEL,STARTTIME, MAX(ALARMLEVELNUM) ");
            strSql.Append("select OBJECTCODE, MAX(ALARMLEVELNUM)  as ALARMLEVEL");
            strSql.Append(" FROM (");
            strSql.Append("select ALARMNUMBER,ENDTIME,ISCLEARED,CLEARPERSON,ALARMEXPLAIN,BELONGEQUIP,BELONGTRANSYS,BELONGSTATION,RECORDDATE,ALARMDESC,PRIMALCAUSE,");
            strSql.Append(" ALARMOBJECT,TRANTYPE,VENDOR,BELONGDOMAIN,EQUIPMODEL,PACKTYPE,PREEQUIP,PRESTATION,DEDUSEFAULT,PERSISTTIME,ISSYNC,OBJECTCODE,OBJCLASS,");
            strSql.Append(" ALARMTYPE,PROBABLECAUSE,ALARMTEXT,ALARMLEVEL,STARTTIME, ");
            strSql.Append("case ALARMLEVEL when '警告告警' then 1 when '次要告警' then 2 when '主要告警' then 3 when '紧急告警' then 4 else 0 end as ALARMLEVELNUM ");
            strSql.Append(" FROM ALARM_INFO ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by OBJECTCODE,ALARMLEVELNUM ");
            strSql.Append(") ");
            strSql.Append(" group by OBJECTCODE");
            return OracleHelper.Query(strSql.ToString());
        }
        public DataSet GetAlarmTop50(string where)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ALARMNUMBER,ENDTIME,ISCLEARED,CLEARPERSON,ALARMEXPLAIN,BELONGEQUIP,BELONGTRANSYS,BELONGSTATION,RECORDDATE,ALARMDESC,");
            strSql.Append(" PRIMALCAUSE,ALARMOBJECT,TRANTYPE,VENDOR,BELONGDOMAIN,EQUIPMODEL,PACKTYPE,PREEQUIP,PRESTATION,DEDUSEFAULT,PERSISTTIME,ISSYNC,");
            strSql.Append(" OBJECTCODE,OBJCLASS,ALARMTYPE,PROBABLECAUSE,ALARMTEXT,ALARMLEVEL,STARTTIME,ISTICKET ");
            strSql.Append(" FROM ( select a.ALARMNUMBER as ALARMNUMBER, a.ENDTIME as ENDTIME,");
            strSql.Append(" a.ISCLEARED as ISCLEARED ,a.CLEARPERSON as CLEARPERSON,");
            strSql.Append(" a.ALARMEXPLAIN as ALARMEXPLAIN,a.BELONGEQUIP as BELONGEQUIP,");
            strSql.Append(" a.BELONGTRANSYS as BELONGTRANSYS,a.BELONGSTATION as BELONGSTATION,");
            strSql.Append(" a.RECORDDATE as RECORDDATE,a.ALARMDESC as ALARMDESC,a.PRIMALCAUSE as PRIMALCAUSE,");
            strSql.Append(" v.name as ALARMOBJECT,a.TRANTYPE as TRANTYPE,");
            strSql.Append(" a.VENDOR as VENDOR,a.BELONGDOMAIN as BELONGDOMAIN,");
            strSql.Append(" a.EQUIPMODEL as EQUIPMODEL,a.PACKTYPE as PACKTYPE,");
            strSql.Append(" a.PREEQUIP as PREEQUIP,a.PRESTATION as PRESTATION,");
            strSql.Append(" a.DEDUSEFAULT as DEDUSEFAULT,a.PERSISTTIME as PERSISTTIME,");
            strSql.Append(" a.ISSYNC as ISSYNC, a.OBJECTCODE as OBJECTCODE, ar.resourcecnname as OBJCLASS,");
            strSql.Append(" a.ALARMTYPE as ALARMTYPE,a.PROBABLECAUSE as PROBABLECAUSE,");
            strSql.Append(" a.ALARMTEXT as ALARMTEXT,a.ALARMLEVEL as ALARMLEVEL,a.STARTTIME as STARTTIME,a.ISTICKET as ISTICKET ");
            strSql.Append(" FROM ALARM_INFO a,v_alarmobject v,alarm_resource ar  ");
            strSql.Append(" where a.objclass = ar.resourcecnname and a.endtime is null  and starttime>(sysdate -1) and  a.alarmobject=v.id  order by starttime desc) ");
            if (where != "" && where != null)
            {
                strSql.Append(" where  " + where);
            }
            //  string strSql = "select ALARMNUMBER,ENDTIME,ISCLEARED,CLEARPERSON,ALARMEXPLAIN,BELONGEQUIP,BELONGTRANSYS,BELONGSTATION,RECORDDATE,ALARMDESC,PRIMALCAUSE,ALARMOBJECT,TRANTYPE,VENDOR,BELONGDOMAIN,EQUIPMODEL,PACKTYPE,PREEQUIP,PRESTATION,DEDUSEFAULT,PERSISTTIME,ISSYNC,OBJECTCODE,OBJCLASS,ALARMTYPE,PROBABLECAUSE,ALARMTEXT,ALARMLEVEL,STARTTIME from (select ALARMNUMBER,ENDTIME,ISCLEARED,CLEARPERSON,ALARMEXPLAIN,BELONGEQUIP,BELONGTRANSYS,BELONGSTATION,RECORDDATE,ALARMDESC,PRIMALCAUSE,ALARMOBJECT,TRANTYPE,VENDOR,BELONGDOMAIN,EQUIPMODEL,PACKTYPE,PREEQUIP,PRESTATION,DEDUSEFAULT,PERSISTTIME,ISSYNC,OBJECTCODE,OBJCLASS,ALARMTYPE,PROBABLECAUSE,ALARMTEXT,ALARMLEVEL,STARTTIME   FROM ALARM_INFO  where  endtime is null  order by starttime desc )  where rownum<50 ";
            return OracleHelper.Query(strSql.ToString());
        }
        public string getAlarmObjectFromResive(string alarmobject)
        {
            string strSql = "select name,id,objtype from v_alarmobject  where  id='" + alarmobject + "'";
            OracleDataReader dr = DBUtility.OracleHelper.ExecuteReader(strSql);
            string chinaname = "";
            while (dr.Read())
            {

                chinaname = dr["NAME"].ToString();
            }
            dr.Close();
            dr.Dispose();
            return chinaname;

        }
        /// <summary>
        /// 获得统计告警的详细数据
        /// </summary>
        /// <param name="whereStr"></param>
        /// <returns></returns>
        public DataSet GetStatisticAlarm(string whereStr)
        {
            string strSql = "select ALARMNUMBER,ENDTIME,ISCLEARED,CLEARPERSON,ALARMEXPLAIN,BELONGEQUIP,BELONGTRANSYS,BELONGSTATION,RECORDDATE,";
            strSql += " ALARMDESC,PRIMALCAUSE,v.name as ALARMOBJECT,TRANTYPE,VENDOR,BELONGDOMAIN,EQUIPMODEL,PACKTYPE,PREEQUIP,PRESTATION,DEDUSEFAULT,";
            strSql += " PERSISTTIME,ISSYNC,OBJECTCODE,OBJCLASS,ALARMTYPE,PROBABLECAUSE,ALARMTEXT,ALARMLEVEL,STARTTIME ";
            strSql += " from ALARM_INFO,v_alarmobject v  WHERE " + whereStr + " and alarmobject=v.id  ";
            return OracleHelper.Query(strSql);
        }
        /// <summary>
        /// 获取告警等级统计数据
        /// </summary>
        /// <returns></returns>
        public DataSet GetAlarmLevelCount()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ALARMLEVEL,count(ALARMLEVEL) as ALARMCOUNT FROM");
            strSql.Append(" (select a.ALARMLEVEL,a.STARTTIME ");
            strSql.Append(" FROM ALARM_INFO a,v_alarmobject v,alarm_resource ar  ");
            strSql.Append(" where a.objclass = ar.resourcecnname and a.endtime is null and a.alarmobject=v.id) ");
            strSql.Append(" where starttime>(sysdate -1) ");
            strSql.Append(" group by ALARMLEVEL");
            return OracleHelper.Query(strSql.ToString());
        }
        /// <summary>
        /// 调用存储过程获取对象告警,如果对象存在下级对象,则同时获取其下级对象的告警
        /// </summary>
        /// <param name="OBJECTID">对象ID</param>
        /// <param name="OBJECTTYPE">对象类型</param>
        /// <param name="OBJECTTEXT">对象文本</param>
        /// <returns></returns>
        public DataSet GetEquipAlarm(string OBJECTID, string OBJECTTYPE, string OBJECTTEXT)
        {
            OracleParameter[] parameters = {
					new OracleParameter("p_id", OracleType.VarChar,25),
                    new OracleParameter("p_type", OracleType.VarChar,200),
                    new OracleParameter("p_text", OracleType.VarChar,200),
                    new OracleParameter("p_cursor", OracleType.Cursor)};
            parameters[0].Value = OBJECTID;
            parameters[1].Value = OBJECTTYPE;
            parameters[2].Value = OBJECTTEXT;

            parameters[0].Direction = System.Data.ParameterDirection.Input;
            parameters[1].Direction = System.Data.ParameterDirection.Input;
            parameters[2].Direction = System.Data.ParameterDirection.Input;
            parameters[3].Direction = System.Data.ParameterDirection.Output;

            return OracleHelper.RunProcedure("GET_ALARM_INFO", parameters, "table1");
        }
        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            OracleParameter[] parameters = {
                    new OracleParameter(":tblName", OracleType.VarChar, 255),
                    new OracleParameter(":fldName", OracleType.VarChar, 255),
                    new OracleParameter(":PageSize", OracleType.Number),
                    new OracleParameter(":PageIndex", OracleType.Number),
                    new OracleParameter(":IsReCount", OracleType.Clob),
                    new OracleParameter(":OrderType", OracleType.Clob),
                    new OracleParameter(":strWhere", OracleType.VarChar,1000),
                    };
            parameters[0].Value = "ALARM_INFO";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return OracleHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  成员方法
    }
}

